<template>
    <div>
        <!-- keChe -->
        <el-row>
            <el-col :span="24">
                <div class="container">
                    <el-row>
                        <el-col :span="24" class="table-fun">
                            <img src="../../assets/imgs/operation_icon_shuaxin_default.png" alt="" class="lf"><div class="lf choose-title2 fun-text" @click="refresh">刷新</div>
                            <img src="../../assets/imgs/operation_icon_tianjia_default.png" alt="" class="lf"><div class="lf choose-title2 fun-text" @click="amWin=true;winTitle='添加'">添加</div>
                            <img src="../../assets/imgs/operation_icon_xiugai_default.png" alt="" class="lf"><div class="lf choose-title2 fun-text" @click="amWin=true;winTitle='修改'">修改</div>
                            <img src="../../assets/imgs/operation_icon_shanchu_default.png" alt="" class="lf"><div class="lf choose-title2 fun-text" @click="del">删除</div>
                            <img src="../../assets/imgs/operation_icon_shuju_default.png" alt="" class="lf"><div class="lf choose-title2 fun-text" @click="tongbu">同步数据中心</div>
                        </el-col>
                    </el-row>
                    <!-- 表格内容 -->
                   <avue-crud :data="kecheList[0].data" :option="kecheList[0].option" @current-row-change="rowChange" :page="kecheList[0].page" @current-change="kechePage"></avue-crud>
                   <!-- 弹窗 -->
                   <div class="modal-win" v-show="amWin">
                     <el-row class="add-title">
                          <div class="closeWin" @click="amWin=false">X</div>
                          <el-col :span="24">
                              <img src="../../assets/imgs/operation_bg_biaoti_default.png" alt=""><span class="add-text">{{winTitle}}</span>
                          </el-col>
                      </el-row>
                      <!-- 表单栏-->
                      <avue-form ref="form" v-model="kecheForm.data" :option="kecheForm.option" class="yz-form"></avue-form>
                      <button class="check-btn rf" @click="amWin=false"><img src="../../assets/imgs/operation_btn_icon_quxiao_default.png" alt="" class="btn-img">取消</button>
                      <button class="check-btn rf" @click="winTitle=='添加'?add():mod()"><img src="../../assets/imgs/operation_btn_icon_tijiao_default.png" alt="" class="btn-img">确认</button>
                   </div>
                </div>
            </el-col>
        </el-row>
        <!-- 同步弹窗 -->
        <div class="tong-win" v-show="tongbuShow">
            <div class="tongbu-text">同步中心数据</div><div class="closeWin" @click="tongbuShow=false">X</div>
            <avue-crud :data="tongbuList.data" :option="tongbuList.option" @current-row-change="rowChange" class="unit-table" @current-change="kechePage" :page="tongbuList.page"></avue-crud>
        </div>
    </div>
</template>

<script>
import qs from "qs";
import MyDialog from "../../components/common/popDilog"
const DIC={
  carType:[
    {
      label:"大型",
      value:"大型"
    },
    {
      label:"中型",
      value:"中型"
    },
    {
      label:"小型",
      value:"小型"
    },
  ],
  seatType:[],
  carLevel:[
    {
      label:"高三级",
      prop:"高三级"
    },
    {
      label:"高二级",
      prop:"高二级"
    },
    {
      label:"高一级",
      prop:"高一级"
    },
    {
      label:"中级",
      prop:"中级"
    },
    {
      label:"普通级",
      prop:"普通级"
    },
  ],
  shangwu:[
    {
      label:"",
      value:"true"
    }
  ]
}
export default {
  data: function() {
    return {
      activeTag:"5-5",
      tongbuTag:false,
      kecheList: [
        {
           page: {
            pageSizes: [10],
            total: 2,
            currentPage: 1,
            pageSize: 10
          },
          data: [],
          option: {
            highlightCurrentRow:true,
            page: true,
            stripe: true,
            menu: false,
            align: "center",
            menuAlign: "center",
            column: []
          }
        }
      ],
      currentRow:"",
      amWin:false,
      winTitle:"test",
      kecheForm:{
        data:{},
        option:{
          dicData:DIC,
          column:[
            {
              label:"车辆类型",
              prop:"carType",
              type:"select",
              dicData:"carType",
              span:8
            },
            {
              label:"座位类型",
              prop:"seatType",  
              type:"select",
              dicData:"seatType",
              span:8
            },
            {
              label:"车辆等级",
              prop:"carLevel",
              type:"select",
              dicData:"carLevel",
              span:8
            },
            {
              label:"对内名称",
              prop:"inName",
              span:12
            },
            {
              label:"对外名称",
              prop:"outName",
              span:12
            },
            {
              label:"车辆基价",
              prop:"carPrice",
              span:16
            },
            {
              label:"商务大巴",
              prop:"shangwuCar",
              type:"checkbox",
              dicData:"shangwu",
              span:20
            },
          ]
        }
      },
      tongbuShow:false,
      tongbuList:{
        page: {
            pageSizes: [10],
            total: 2,
            currentPage: 1,
            pageSize: 10},
        data:[],
        option:{
          menu:false,
          page:true,
          column:[
            {
              label:"车型",
              prop:"vehi_type"
            },
            {
              label:"基价",
              prop:"base_price"
            },
          ]
        }
      }
    };
  },
  methods: {
    getSeatType(){
      this.postRequest("/sch/data/common/busseattype").then(data=>{
        for(var item of data.data){
          DIC.seatType.push({
            label:item.value,
            value:item.key
          })
        }
      })
    },
    kechePage(val){
      this.kecheList[0].page.currentPage=val;
      if(this.tongbuTag==false){
        this.getKeCheList();
      }else{
        this.tongbu();
      }
    },
    getKeCheList() {
      this
        .postRequest("/sch/const/bus_vehicle_type/list",{
          rows:10,
          page:this.kecheList[0].page.currentPage
        })
        .then(data => {
          this.kecheList[0].page.total=data.data.totalRow
          this.kecheList[0].data=data.data.list;
        });
    },
    refresh() {
      this.kecheList[0].page.currentPage=1
      this.getKeCheList();
    },
    add() {
      this
        .getRequest(
          "/sch/const/bus_vehicle_type/add?busVehicleType.id=&busVehicleType.vehi_type="+this.kecheForm.data.carType+"&busVehicleType.seat_type="+this.kecheForm.data.seatType+"&busVehicleType.vehi_rank="+this.kecheForm.data.carLevel+"&busVehicleType.name_in="+this.kecheForm.data.inName+"&busVehicleType.name_out="+this.kecheForm.data.outName+"&busVehicleType.base_price="+this.kecheForm.data.carPrice+"&busVehicleType.is_buss="+this.kecheForm.data.shangwuCar
        )
        .then(data => {
          if (data.data[0] == 0) {
            this.$message({
              message: data.data[1],
              type: "success"
            });
            this.getKeCheList();
            this.amWin=false;
          } else {
            this.$message.error(data.data[1]);
          }
        });
    },
    mod() {
      this
        .getRequest(
          "/sch/const/bus_vehicle_type/update?busVehicleType.id="+this.currentRow.id+"&busVehicleType.vehi_type="+this.kecheForm.data.carType+"&busVehicleType.seat_type="+this.kecheForm.data.seatType+"&busVehicleType.vehi_rank="+this.kecheForm.data.carLevel+"&busVehicleType.name_in="+this.kecheForm.data.inName+"&busVehicleType.name_out="+this.kecheForm.data.outName+"&busVehicleType.base_price="+this.kecheForm.data.carPrice+"&busVehicleType.is_buss="+this.kecheForm.data.shangwuCar
        )
        .then(data => {
          if (data.data[0] == 0) {
            this.$message({
              message: data.data[1],
              type: "success"
            });
            this.getKeCheList();
            this.amWin=false;
          } else {
            this.$message.error(data.data[1]);
          }
        });
    },
    del() {
      this
        .postRequest(
          "/sch/const/bus_vehicle_type/del",{
            id:this.currentRow.id
          }
        )
        .then(data => {
          if (data.data[0] == 0) {
            this.$message({
              message: data.data[1],
              type: "success"
            });
            this.getKeCheList();
          } else {
            this.$message.error(data.data[1]);
          }
        });
    },
    tongbu(){
      this.tongbuShow=true;
      this.tongbuTag=true;
      this.postRequest("/sync/center/data/base/vehitype",{
        rows:10,
        page:this.tongbuList.page.currentPage
      }).then(data=>{
        this.tongbuList.page.total=data.data.totalRow
        this.tongbuList.data=data.data.list;
      })
    },
    tableCreate() {
      this.kecheList[0].option.column.push(
        {
          label: "对内名称",
          prop: "name_in"
        },
        {
          label: "对外名称",
          prop: "name_out"
        },
        {
          label: "车辆类型",
          prop: "vehi_type"
        },
        {
          label: "座位类型",
          prop: "seat_type"
        },
        {
          label: "车辆等级",
          prop: "vehi_rank"
        },
        {
          label: "车辆基价",
          prop: "base_price"
        },
        {
          label: "商务大巴",
          prop: "is_buss"
        },
      );
    },
    rowChange(val){
      this.currentRow=val;
      this.kecheForm.data.carType=val.vehi_type;
      this.kecheForm.data.seatType=val.seat_type;
      this.kecheForm.data.carLevel=val.vehi_rank;
      this.kecheForm.data.inName=val.name_in;
      this.kecheForm.data.outName=val.name_out;
      this.kecheForm.data.carPrice=val.base_price;
      this.kecheForm.data.shangwuCar=val.is_buss;
      if(this.winTitle=="添加"){
        this.kecheForm.data.carType="";
        this.kecheForm.data.seatType="";
        this.kecheForm.data.carLevel="";
        this.kecheForm.data.inName="";
        this.kecheForm.data.outName="";
        this.kecheForm.data.carPrice="";
        this.kecheForm.data.shangwuCar="";
      }
    }
  },
  computed: {},
  components:{MyDialog},
  watch: {
    winTitle(){
      if(this.winTitle=="添加"){
        this.kecheForm.data.carType="";
        this.kecheForm.data.seatType="";
        this.kecheForm.data.carLevel="";
        this.kecheForm.data.inName="";
        this.kecheForm.data.outName="";
        this.kecheForm.data.carPrice="";
        this.kecheForm.data.shangwuCar="";
      }
    }
  },
  mounted() {
    console.log("keche");
    this.$emit("sendActive",this.activeTag);
    this.tableCreate();
    this.getKeCheList();
    this.getSeatType();
  }
};
</script>
<style scoped src="../../assets/css/service/keche.css">

</style>